package com.mzxy.boxuegu.activity;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.mzxy.boxuegu.R;
import com.mzxy.boxuegu.utils.Constants;
import com.mzxy.boxuegu.utils.SpUtils;

public class SettingActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView tvMainTitle;
    private TextView tvBack;
    private RelativeLayout rlModifyPsw;
    private RelativeLayout rlSecuritySetting;
    private RelativeLayout rlExitLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        findViewById(R.id.title_bar).setBackgroundColor(Color.parseColor("#30B4FF"));
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        tvMainTitle.setText("设置");

        //找到这四个空间
        tvBack = (TextView) findViewById(R.id.tv_back);
        rlModifyPsw = (RelativeLayout) findViewById(R.id.rl_modify_psw);
        rlSecuritySetting = (RelativeLayout) findViewById(R.id.rl_security_setting);
        rlExitLogin = (RelativeLayout) findViewById(R.id.rl_exit_login);

        //注册事件监听
        tvBack.setOnClickListener(this);
        rlModifyPsw.setOnClickListener(this);
        rlSecuritySetting.setOnClickListener(this);
        rlExitLogin.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_back:
                finish();
                break;
            case  R.id.rl_modify_psw:
                startActivity(new Intent(this,ModifyPswActivity.class));
                break;
            case  R.id.rl_security_setting:
                Intent intent = new Intent(this,FindPswActivity.class);
                intent.putExtra("isfindpsw",false); //设置为false 告诉FindPswActivity显示设置密保
                startActivity(intent);
                break;
            case  R.id.rl_exit_login:
                SpUtils.saveLoginStatus(this,false);
                SpUtils.saveLoginUsername(this,"");
                Toast.makeText(this,"退出登陆成功",Toast.LENGTH_SHORT).show();

                Intent data = new Intent();
                data.putExtra("exitLogin",true);
                setResult(Constants.SETTING2MYINFO_RESULT_CODE,data);
                finish();
                break;
        }
    }
}
